﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;

using SynergyControls;
using SynergyLib.DSP;
using SharpDX.XAudio2;

namespace XAudio2Controls
{
    public class TremoloPanel: EffectsPanel, IEffectParams
    {
        public float ModFreq
        {
            get { return DialAngle1 / 360 * 20; }
            
        }
        public TremoloEffect trem { get; set; }

         static TremoloPanel()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TremoloPanel), new FrameworkPropertyMetadata(typeof(EffectsPanel)));
        }

        public TremoloPanel(SubmixVoice submixer, Collection<EffectDescriptor> fxChainReference)
        {
            FxChain = fxChainReference;
            EffectParams = this;
            effectType = EffectTypes.Tremolo;
            Submixer = submixer;            
            this.Effect = new TremoloEffect();
            //this.Effect = new DelayVibratoEffect();
            trem = (TremoloEffect)Effect;
            this.effectDescriptor = new EffectDescriptor(Effect);
        }

        protected override void UpdateParameters()
        {
            if (ParameterEnabled)
            {
              
                TremoloParams prms = new TremoloParams()
                {
                    ModulationFrequency = this.Param1,                  
                };
                trem.Parameters = prms;
                
            }
        }
        protected override void UpdateIntensity()
        {
            trem.Intensity = (float)IntensitySliderValue;
        }

        #region IEffectParams
        public float Param1
        {
            get
            {
                ParamLabel1Content = GetParam1Readout();
                return ModFreq;
            }
        }
        public float Param2
        {
            get;
            set;
        }
        public float Param3
        {
            get;
            set;
        }
        public float Param4
        {
            get;
            set;
        }

        public string ParamName1
        {
            get
            {
                return "ModFreq";
            }
        }
        public string ParamName2
        {
            get
            {
                return GetParam2Readout();
            }
        }
        public string ParamName3
        {
            get
            {
                return GetParam3Readout();
            }
        }
        public string ParamName4
        {
            get
            {
                return GetParam4Readout();
            }
        }

        public string GetParam1Readout()
        {
            return Math.Round(ModFreq, 2).ToString() + "Hz";
        }
        public string GetParam2Readout()
        {
            return null;
        }
        public string GetParam3Readout()
        {
            return null;
        }
        public string GetParam4Readout()
        {
            return null;
        }
        #endregion IEffectParams
    }
}
